/**
 * @project name:crm
 */
package com.yunbo.crm.controller;

import com.yunbo.crm.base.BaseController;
import com.yunbo.crm.base.ResultInfo;
import com.yunbo.crm.pojo.CusDevPlan;
import com.yunbo.crm.query.CusDevPlanQuery;
import com.yunbo.crm.service.CusDevPlanService;
import com.yunbo.crm.service.SaleChanceService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @Author : yun&bo
 * @CreateDate : ==>2021/1/24 12:58
 * @ClassName : ==>
 * @Description : ==>
 * @Version
 */

@RestController
@RequestMapping("cus_dev_plan")
public class CusDevPlanController extends BaseController {

    @Resource
    private SaleChanceService saleChanceService;
    @Resource
    private CusDevPlanService cusDevPlanService;

    @GetMapping("index")
    public ModelAndView index(ModelAndView modelAndView) {
        modelAndView.setViewName("cusDevPlan/cus_dev_plan");
        return modelAndView;
    }

    /**
     * 前往 开发操作/详情页
     *
     * @param modelAndView
     * @param sid
     * @return
     */
    @GetMapping("toCusDevPlanDataPage")
    public ModelAndView toCusDevPlanDataPage(ModelAndView modelAndView, Integer sid) {
        modelAndView.setViewName("cusDevPlan/cus_dev_plan_data");
        modelAndView.addObject("saleChance", saleChanceService.selectByPrimaryKey(sid));
        return modelAndView;
    }

    @GetMapping("list")
    public Map<String, Object> queryCusDevPlansByParams(CusDevPlanQuery cusDevPlanQuery) {
        return cusDevPlanService.querCusDevPlansByParams(cusDevPlanQuery);
    }

    /**
     * 去添加计划项/编辑
     *
     * @param modelAndView
     * @return
     */
    @GetMapping("addOrUpdateCusDevPlanPage")
    public ModelAndView addOrUpdateCusDevPlanPage(Integer sid, Integer rowId, ModelAndView modelAndView) {
        System.out.println("sid+rowId" + sid + rowId);
        modelAndView.setViewName("cusDevPlan/add_update");
        CusDevPlan cusDevPlanNew = cusDevPlanService.selectByPrimaryKey(rowId);
        modelAndView.addObject("cusDevPlan", cusDevPlanNew);
        modelAndView.addObject("sid", sid);
        return modelAndView;
    }

    /**
     * 保存新的规划
     *
     * @param request
     * @return
     */
    @PostMapping("save")
    public ResultInfo saveCusDevPlan(CusDevPlan cusDevPlan, HttpServletRequest request) {
        cusDevPlanService.saveCusDevPlan(cusDevPlan, request);
        return success();
    }

    @PutMapping("edit")
    public ResultInfo updateCusDevPlan(CusDevPlan cusDevPlan, HttpServletRequest request) {
        cusDevPlanService.updateCusDevPlan(cusDevPlan, request);
        return success("计划更新成功");
    }

    @DeleteMapping("delete")
    public ResultInfo deleteCusDevPlan(CusDevPlan cusDevPlan) {
        cusDevPlanService.deleteByPrimaryKey(cusDevPlan.getRowId());
        return success("删除成功");
    }




}
